<?php


namespace app\admin\controller;

use app\admin\model\Role as RoleModel;
use app\admin\validate\Role as RoleValidate;

class Role extends Base
{
    protected function _initialize()
    {
        //如果要检测token,就调用父类_initialize方法
//        parent::_initialize();
    }

    public function index()
    {
        $data['data'] = RoleModel::all();
        $data['total'] = RoleModel::count();
        return $this->ok($data);
    }

    public function save()
    {
        (new RoleValidate())->goCheck();
        $params = input();
//        echo "<pre>";
//        print_r($params);die;
        //$params['img']是url字符串

        //创建顶级分类,或者创建某分类的子分类
        RoleModel::create($params, true);
        return $this->ok([], '创建角色成功');
    }
}